﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MasterSheetManager.Utl;
using MasterSheetManager.Models;

namespace MasterSheetManager.Controllers
{
    public class ParticipantController : Controller
    {
        //
        // GET: /Participant/

        public ActionResult Index(string search)
        {
            return View();
        }

        public PartialViewResult Search(string where)
        {
            if (string.IsNullOrWhiteSpace(where))
            {
                return PartialView("SearchResult", CH.DB.Participant.ToList());
            }
            else
            {
                return PartialView("SearchResult", CH.DB.Participant.Where(s =>
                    s.Name.Contains(where) ||
                    s.ID.ToString().Contains(where) ||
                    s.Deal.CompanyRelationship.Company.Name_CH.Contains(where) ||
                    s.Deal.CompanyRelationship.Company.Name_EN.Contains(where) ||
                    s.Mobile.Contains(where) ||
                    s.Email.Contains(where)).ToList());
            }
        }

        public JsonResult Confirm(int? ParticipantID, DateTime? ArrivalDateTime)
        {
            if (ParticipantID != null && !CH.DB.Arrival.Any(s => s.ParticipantID == ParticipantID))
            {
                CH.Create<Arrival>(new Arrival() { ParticipantID = ParticipantID, ArrivalDateTime = ArrivalDateTime, IsArrived = true });
            }
            return Json("", JsonRequestBehavior.AllowGet);
        }
    }
}
